#include <init.h>
#include <common.h>
#include <driver.h>
#include <net.h>
#include <io.h>
#include <xfuncs.h>
#include <errno.h>
#include <linux/phy.h>
#include "ag71xx.h"

static int ag71xx_hw_init(struct ag71xx *ag)
{	
    return 0;
}

static int ag71xx_open(struct eth_device *edev)
{
	return 0;
}

static int ag71xx_send(struct eth_device *edev, void *packet, int length)
{
	return 0;
}

static int ag71xx_recv(struct eth_device *edev)
{
	return 0;
}

static void ag71xx_halt(struct eth_device *edev)
{

}

static int ag71xx_get_ethaddr(struct eth_device *edev, u8 *addr)
{
	return 0;
}

static int ag71xx_set_ethaddr(struct eth_device *edev, const u8 *addr)
{
	return 0;
}

static int ag71xx_miibus_read(struct mii_bus *bus, int phy_id, int regnum)
{
	return 0;
}

static int ag71xx_miibus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
{
	return 0;
}

static int ag71xx_probe(struct device_d *dev)
{
	int ret;
	struct resource *iores;
	struct ag71xx *priv;
	struct eth_device *edev;

	priv = xzalloc(sizeof(struct ag71xx));
	edev = &priv->edev;
	edev->priv = priv;

	iores = dev_request_mem_resource(dev, 0);
	if (IS_ERR(iores)) {
		ret = PTR_ERR(iores);
		goto err;
	}
	priv->mac_base = IOMEM(iores->start);

	edev->open = ag71xx_open;
	edev->send = ag71xx_send;
	edev->recv = ag71xx_recv;
	edev->halt = ag71xx_halt;
	edev->get_ethaddr = ag71xx_get_ethaddr;
	edev->set_ethaddr = ag71xx_set_ethaddr;

	priv->miibus.read = ag71xx_miibus_read;
	priv->miibus.write = ag71xx_miibus_write;
	priv->miibus.priv = priv;
	priv->miibus.parent = dev;

	ag71xx_hw_init(priv);
		
	mdiobus_register(&priv->miibus);
	eth_register(edev);

	return 0;
	
err:
	free(edev);
	return ret;
}

static struct of_device_id ag71xx_of_matches[] = {
	{ .compatible = "atheros,ag71xx", },
	{ /* sentinel */ }
};

static struct driver_d ag71xx_driver = {
	.name  = "ag71xx",
	.probe = ag71xx_probe,
	.of_compatible = DRV_OF_COMPAT(ag71xx_of_matches),
};

device_platform_driver(ag71xx_driver);
